package kr.co.graviti.adm.auth.action;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import kr.co.graviti.adm.common.dao.AdmCommonDAO;
import kr.co.graviti.common.util.CommonUtil;
import kr.co.graviti.common.util.Crypto;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

public class AdminInfoModifyAction extends DispatchAction{
	
	private static final Logger _log = Logger.getLogger(AdminInfoModifyAction.class);
	
	public ActionForward getAdminInfoList(ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,HttpServletResponse response)
	        throws Exception {
		
		HashMap req = new HashMap();
		req = CommonUtil.getRequest(request);
		
		HttpSession session = request.getSession();
		String adminId = (String)session.getAttribute("admId");
		
		req.put("userid", adminId);		//	아이디 값을 세션 객체에서 가져온다.
		
		AdmCommonDAO admCommonDAO = new AdmCommonDAO();
		String ibatisNm = "admauth";
		HashMap adminInfo = admCommonDAO.getHashMapDAO(req, ibatisNm + ".selectAdmInfo");
		
		request.setAttribute("adminInfo", adminInfo);
		
		return mapping.findForward("admmodify");
	}
	
	public ActionForward updateAdminInfo(ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,HttpServletResponse response)
	        throws Exception {
		
		HashMap req = new HashMap();
		req = CommonUtil.getRequest(request);
		
		HttpSession session = request.getSession();
		String adminId = (String)session.getAttribute("admId");
		req.put("userid", adminId);		//	아이디 값을 세션 객체에서 가져온다.
		
		String passwd = (String)req.get("passwd");
		String decodePwd = new Crypto().encryption(passwd);
		req.put("passwd", decodePwd);
		
		
		AdmCommonDAO admCommonDAO = new AdmCommonDAO();
		String ibatisNm = "admauth";
		admCommonDAO.setUpdateDAO(req, ibatisNm + ".updateAdminInfoByUserid");
		
		return mapping.findForward("admmain");
	}

}
